# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=antlr4
pkgbase=mingw-w64-${_realname}-runtime-cpp
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-runtime-cpp"
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git"
          "${MINGW_PACKAGE_PREFIX}-${_realname}-runtime-cpp-git")
pkgver=4.8
pkgrel=1
pkgdesc="ANother Tool for Language Recognition v4 (mingw-w64)"
arch=('any')
url="https://www.antlr.org/"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}-${pkgver}.tar.gz::https://codeload.github.com/antlr/antlr4/tar.gz/${pkgver}"
        "antlr4-install-dll-to-bin.patch")
sha256sums=('992d52444b81ed75e52ea62f9f38ecb7652d5ce2a2130af143912b3042a6d77e'
            'f57b5d23b300dd9055f957f85dd44923e12e92277c3dcb2a2dcbdc9c6138f908')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/antlr4-install-dll-to-bin.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    "../${_realname}-${pkgver}/runtime/Cpp"

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
